package TV;

public class Television {
    private static int nextId = 1;

    // 实例变量
    private int id;
    private boolean isOn;
    private int volume;
    private int channel;

    // 构造器
    public Television() {
        this.id = nextId++;
        this.isOn = false;
        this.volume = 10; // 默认音量
        this.channel = 1; // 默认频道
    }

    // 静态方法，用于切换电视机的开关状态
    public static void turnOnOff(Television tv) {
        tv.isOn = !tv.isOn;
    }

    // 更改当前频道
    public void changeChannel(int newChannel) {
        if (isOn && newChannel > 0) {
            this.channel = newChannel;
        }
    }

    // 增加音量
    public void increaseVolume() {
        if (isOn && volume < 100) {
            this.volume++;
        }
    }

    // 减少音量
    public void decreaseVolume() {
        if (isOn && volume > 0) {
            this.volume--;
        }
    }

    // 返回电视机当前状态的字符串表示
    @Override
    public String toString() {
        return "Television{" +
                "id=" + id +
                ", isOn=" + isOn +
                ", volume=" + volume +
                ", channel=" + channel +
                '}';
    }

    // 主方法，用于测试
    public static void main(String[] args) {
        Television tv1 = new Television();
        System.out.println(tv1);

        turnOnOff(tv1);
        System.out.println(tv1);

        tv1.changeChannel(5);
        tv1.increaseVolume();
        System.out.println(tv1);

        turnOnOff(tv1);
        System.out.println(tv1);
    }
}
